// utils/request.js 封装接口，在每次请求时带上token
const baseUrl = 'http://106.52.12.104:8089'; // 替换为你的接口基础路径

function request(url, method = 'GET', data = {}, header = {}) {
  return new Promise((resolve, reject) => {
    // 从本地存储获取 token
    const token = wx.getStorageSync('token');
    
    // 将 token 加入 header
    if (token) {
      header['token'] = token;
    }

    wx.request({
      url: baseUrl + url,
      method: method,
      data: data,
      header: header,
      success: (res) => {
        if (res.statusCode === 200) {
          resolve(res.data);
        } else {
          reject(res.data);
        }
      },
      fail: (err) => {
        reject(err);
      }
    });
  });
}

module.exports = {
  request
};
